<template>
  <view class="sign-up">
    <view class="card">
      <text class="h1"> 活动报名 </text>
      <text class="h3"> 诚邀您的参加 </text>
    </view>

<!--    <view class="title"> 活动报名 </view>-->

    <view class="sign-up-form">
      <up-form
        labelPosition="left"
        :model="signUpModel"
        :rules="signUpModel.rules"
        ref="form1"
      >
        <up-form-item
          label="姓名"
          labelWidth="auto"
          prop="form.userName"
          ref="item1"
        >
          <up-input
            v-model="signUpModel.form.userName"
            placeholder-class="plaClass"
            placeholder="请输入姓名"
            border="none"
            input-align="right"
          />
        </up-form-item>

        <up-form-item label="工作单位" labelWidth="auto" ref="item1">
          <up-input
              v-model="signUpModel.form.wechat"
              placeholder-class="plaClass"
              placeholder="请输入工作单位"
              border="none"
              input-align="right"
          />
        </up-form-item>

        <up-form-item
          label="电话"
          labelWidth="auto"
          prop="form.userPhone"
          ref="item1"
        >
          <up-input
              type="number"
            v-model="signUpModel.form.userPhone"
            placeholder-class="plaClass"
            placeholder="请输入电话"
            border="none"
            input-align="right"
          />
        </up-form-item>

        <up-form-item label="职务" labelWidth="auto" ref="item1">
          <up-input
              v-model="signUpModel.form.job"
              placeholder-class="plaClass"
              placeholder="请输入职务"
              border="none"
              input-align="right"
          />
        </up-form-item>

      </up-form>
    </view>

    <view class="submit-btn">
      <view class="btn" @tap="handleSubmitSignUpForm"> 立即报名 </view>
    </view>
  </view>
  <custom-dialog
    v-if="popDialogShowFlag"
    title="报名成功"
    @close-btn-click="handleDialogCloseBtnClick"
  >
    <view class="text-content">
      <text class="text"> 恭喜你报名成功，请按时参加活动 </text>
    </view>
    <view class="btn-group">
      <text class="btn" @tap="handleDialogCloseBtnClick">我知道了</text>
    </view>
  </custom-dialog>
</template>
<script setup>
import { ref, reactive } from "vue";
import { onShow } from "@dcloudio/uni-app";
import { getUrlParamsInH5, getUrlParamsInWeixin } from "../../utils/utils";
import {getActivityDetailTicketTotalApi, userSubmitSignUpActivityFormApi} from "../../api/activity";
import CustomDialog from "@/components/CustomDialog";
import { customNav } from "../../utils/customNav";
import UniListItem from "@/uni_modules/uni-list/components/uni-list-item/uni-list-item.vue";

const popDialogShowFlag = ref(false);
const signUpModel = ref({
  form: {
    userName: "",
    userPhone: "",
    wechat: "",
    job: ""
  },
});

/**
 * 立即报名按钮点击事件监听
 * @returns {Promise<void>}
 */
const handleSubmitSignUpForm = async () => {

  if (signUpModel.value.form.userName === "") {
    await uni.showToast({
      icon: "none",
      title: '请输入您的姓名',
      duration: 3000
    })
  }else if (signUpModel.value.form.wechat === "") {
    await uni.showToast({
      icon: "none",
      title: '请输入您的工作单位',
      duration: 3000
    })
  }else if (signUpModel.value.form.userPhone === "") {
    await uni.showToast({
      icon: "none",
      title: '请输入您的电话',
      duration: 3000
    })
  }

  else {
    await uni.showLoading({
      title: "正在报名...",
    });
    const params = {
      activityId: activityId.value,
      userName: signUpModel.value.form.userName,
      userPhone: signUpModel.value.form.userPhone,
      enterpriseName: signUpModel.value.form.wechat,
      job: signUpModel.value.form.job,
    }

    console.log("报名参数",params);
    const res = await userSubmitSignUpActivityFormApi(params);
    const { code, data } = res;
    if (code === 200) {
      uni.hideLoading();
      popDialogShowFlag.value = true;
    } else if (code === 400) {
      uni.hideLoading();
    }
  }
};
const handleDialogCloseBtnClick = () => {
  popDialogShowFlag.value = false;
  // customNav("/package_activity/pages/activity/activity-home");
  uni.navigateBack()
};

const activityId = ref("");
onShow(() => {
  /* #ifdef MP-WEIXIN */
  activityId.value = getUrlParamsInWeixin()?.activityId;
  enterpriseType.value = getUrlParamsInWeixin()?.enterpriseType
  /* #endif */

  /* #ifndef MP-WEIXIN */
  activityId.value = getUrlParamsInH5()?.activityId;
  /* #endif */

  getActivityDetailTicketTotal()
});
</script>
<style lang="less" scoped>
.sign-up {
  height: calc(100vh - 120rpx);
  background-color: @color-origin-white;
  padding: 21rpx 30rpx;
  .card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 688rpx;
    height: 228rpx;
    background: @activity-sign-up-card-img;
    background-size: cover;
    font-family: "ali-m";
    color: @color-origin-white;
    .h1 {
      font-size: 39rpx;
    }
    .h3 {
      font-size: 31rpx;
    }
  }

  .title {
    margin-top: 50rpx;
    font-family: "ali-p";
    font-weight: 500;
    font-size: 31rpx;
    color: @color-black-text;
  }
  .sign-up-form {
    margin-top: 58rpx;
    :deep(.u-form-item__body) {
      margin-bottom: 28rpx;
      //border-bottom: 1px solid @color-light-grey-border;
    }
    :deep(.u-form-item__body) {
      justify-content: space-between;
    }
    :deep(.u-form-item__body__right) {
      max-width: 271rpx;
    }
    :deep(.u-form-item__body__left__content__label) {
      font-family: "ali-p";
      font-size: 31rpx;
      color: @color-black-text;
    }
    :deep(.plaClass) {
      text-align: right;
    }
    :deep(.u-input__content) {
      padding-right: 20rpx;
    }
  }
  .submit-btn {
    display: flex;
    align-items: center;
    position: fixed;
    bottom: 0;
    width: 100vw;
    height: 111rpx;
    box-sizing: border-box;
    background-color: @color-origin-white;
    .btn {
      width: 706rpx;
      height: 65rpx;
      line-height: 65rpx;
      border-radius: 33rpx;
      background: @linear-gradient-btn;
      font-family: "ali-p";
      font-size: 33rpx;
      color: @color-origin-white;
      font-weight: 500;
      text-align: center;
    }
  }
}
// :deep(.text-content) {
//   display: flex;
//   flex-direction: column;
//   align-items: center;
//   margin-top: 52rpx;

//   .text {
//     font-family: 'ali-p';
//     font-size: 23rpx;
//     color: @color-grey-text;
//     font-weight: 400;
//     line-height: 39rpx;
//   }

// }
:deep(.mask) {
  .popup-dialog {
    padding: 30rpx 60rpx;
    text-align: center;
    .text {
      line-height: 100rpx;
      font-size: @font-size-23;
      color: @color-grey-text;
    }
    .btn-group {
      padding: 0 0;
    }
  }
  // display: flex;
  // flex-direction: column;
  // align-items: center;
  // margin-top: 52rpx;

  // .text {
  //   font-family: 'ali-p';
  //   font-size: 23rpx;
  //   color: @color-grey-text;
  //   font-weight: 400;
  //   line-height: 39rpx;
  // }
}
.btn-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: @color-blue-text;
  font-family: "ali-p";
  font-size: 31rpx;
  line-height: 39rpx;
  margin-top: 40rpx;
  padding-bottom: 40rpx;
  .btn {
    margin-top: 20rpx;
  }
}

.uni-list-item__container, .container--right {
  padding: 0;
}
.uni-list-item__extra-text {
  font-size: 15rpx;
}
.uni-list--border:after {
  background-color: #ffffff;
}

.uni-input {
  text-align: right;
  position: relative;
  right: 20rpx;
}
</style>
